﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;

namespace Member
{
    class AccessDB
    {
        public OleDbConnection _connection = new OleDbConnection();
        public String ConnectionString;
        public AccessDB()
        {
            string dbFilePath = Application.StartupPath + "\\cashier.mdb";
            this.ConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data source= {0}",dbFilePath);
            this._connection = new OleDbConnection(this.ConnectionString);
        }
        public void OpenConnection()
        {
            this._connection.Open();        
        }
        public void CloseConnection()
        {
            this._connection.Close();
        }
        public DataSet ExeQuery(String strSQL)
        {
            DataSet daset = new DataSet();
            if (_connection.State == ConnectionState.Closed)
            {
                this._connection.Open();
                OleDbDataAdapter DataAdapter = new OleDbDataAdapter(strSQL, this._connection);
                DataAdapter.Fill(daset);
                this._connection.Close();
            }
            return daset;
        }
        public int ExeNonQuery(String strSQL)
        {
            if (_connection.State == ConnectionState.Closed)
                this._connection.Open();
            OleDbCommand SQLcomd = new OleDbCommand(strSQL, this._connection);
            SQLcomd.CommandType = CommandType.Text;
            int rowsAffected = SQLcomd.ExecuteNonQuery();
            this._connection.Close();
            return rowsAffected;
        }
        public void ExSQLtoDGV(String strSQL, DataGridView DTG)
        {
            DTG.DataSource = ExeQuery(strSQL).Tables[0];
        }
       
    }
}
